package com.baizhi.service.impl;

import com.baizhi.config.log.LogAnnotation;
import com.baizhi.entity.CmfzLog;
import com.baizhi.mapper.CmfzLogMapper;
import com.baizhi.service.CmfzLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class CmfzLogServiceImpl implements CmfzLogService {
    @Autowired
    private CmfzLogMapper cmfzLogMapper;
    @Transactional
    @LogAnnotation(content = "日志信息展示",type = "select")
    public Map selectPage(Integer pageNum, Integer pageSize,String option,String search) {
        Map map = new HashMap();
        if(option==null||option.isEmpty()||search==null||search.isEmpty()){
            Page<CmfzLog> page = new Page<>(pageNum,pageSize);
            Page<CmfzLog> cmfzLogPage = cmfzLogMapper.selectPage(page, null);
            List<CmfzLog> cmfzLogs = cmfzLogPage.getRecords();
            long total = cmfzLogPage.getTotal();
            map.put("code",0);
            map.put("data",cmfzLogs);
            map.put("count",total);
        }else{
            Page<CmfzLog> page2 = new Page<>(pageNum,pageSize);
            QueryWrapper<CmfzLog> wrapper = new QueryWrapper<>();
            wrapper.eq(option,search);
            Page<CmfzLog> cmfzLogPage = cmfzLogMapper.selectPage(page2, wrapper);
            List<CmfzLog> cmfzLogs = cmfzLogPage.getRecords();
            long total = cmfzLogPage.getTotal();
            map.put("code",0);
            map.put("data",cmfzLogs);
            map.put("count",total);
        }

        return map;
    }
}
